package 斗地主游戏1控制台版;

import java.util.*;

public class PokerGame2 {
    TreeSet<Integer> lord = new TreeSet<>();
    TreeSet<Integer> player1 = new TreeSet<>();
    TreeSet<Integer> player2 = new TreeSet<>();
    TreeSet<Integer> player3 = new TreeSet<>();


    //此时我们只要把牌跟序号产生对应关系就可以了
    //不需要按照序号进行排序，所以只要HashMap就可以了
    //
    static HashMap<Integer,String> hm=new HashMap<>();
    static ArrayList<Integer> list=new ArrayList<>();
    //静态代码块
    //特点：随着类的加载而加载，而且只执行一次

    //准备牌
    static {
        //"♣", "♦", "♥" ,"♠"
        //序号
        int serialNumber=1;
        String[] color = {"♣", "♦", "♥", "♠"};
        String[] number = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        //牌盒
        for (String n : number) {
            //c:表示每一种花色
            for (String c : color) {
                //n ：表示每一个数字
                hm.put(serialNumber,c+n);
                serialNumber++;
            }
        }
        hm.put(serialNumber++,"小王");
        hm.put(serialNumber,"大王");
        System.out.println(hm);



    }

    public PokerGame2() {
        list.addAll(hm.keySet());
        Collections.shuffle(list);
        //发牌
        for (int i = 0; i < list.size(); i++) {
            Integer number = list.get(i);
            if (i <= 2) {
                lord.add(number);
                continue;
            }
            //给三个玩家轮流发牌
            if (i % 3 == 0) {
                player1.add(number);
            } else if (i % 3 == 1) {
                player2.add(number);
            }
            else {
                player3.add(number);
            }
        }
        lookPoker("玩家一", player1);
        Pokerphoto("玩家一",player1);
        lookPoker("玩家二", player2);
        Pokerphoto("玩家二", player2);
        lookPoker("玩家三", player3);
        Pokerphoto("玩家三", player3);
        lookPoker("底牌", lord);
        Pokerphoto("底牌", lord);



    }
    public void lookPoker(String name, TreeSet<Integer> list) {
        System.out.print(name + ": ");
        System.out.print(list);
        System.out.println();
    }
    public void Pokerphoto(String name,TreeSet<Integer> list){
        System.out.print(name + ": ");
        for (int i : list) {
            System.out.print(hm.get(i));
        }
        System.out.println();
    }
}
